import _ from "lodash";
import { ICmpnt } from "xcore/cmpnt";
import { func } from "xcode/data";
import { AttrHandler, IPropertyItem } from "../../types";

import { EnumProperty } from "xcore/cmpnt/types";
import { nextTick, onMounted } from "vue";


export const getRemoveAttrs: AttrHandler = (pis: IPropertyItem[], cmpnt: ICmpnt) => {
    //添加删除组件
    onMounted(() => {
        nextTick(() => {
            _.delay(() => {
                let del: IPropertyItem = { icon: "fa fa-remove", label: "删除组件", devided: true }
                let delExists = pis.some(item => item.label === del.label);
                if (!delExists && cmpnt.props.bind && cmpnt.props.bind.properties) {
                    if (cmpnt.props.bind.properties.findIndex(item => item === EnumProperty.Removed) < 0) {
                        return;
                    }
                    del.events = {}
                    del.events.click = function () {
                        func.removeCmpnt(cmpnt)
                    }
                    pis.push(del)
    
                }
            }, 500);
        })
    })
    
}